//
//  ViewController.m
//  UI_19_数据请求model嵌套
//
//  Created by li cheng on 16/8/10.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "FindCar.h"
#import "Result.h"
#import "Brandlist.h"
#import "Brand.h"
#import "CustomTableViewcellTableViewCell.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *carBrabdImageView;
@property (nonatomic,strong) FindCar *findCar;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self handleData];
}
- (void)handleData{
    NSString *path  = [[NSBundle mainBundle] pathForResource:@"File" ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSError *error = nil;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
    //
    self.findCar = [FindCar modelWithDictionary:dic];
//    NSLog(@"-------%@", findCar.result.class);
    
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return self.findCar.result.brandlist[section].letter;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.findCar.result.brandlist.count;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.findCar.result.brandlist[section].list.count;
//return self.findCar.result.brandlist.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CustomTableViewcellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    Brand *brand = self.findCar.result.brandlist[indexPath.section].list[indexPath.row];
    cell.MyLabel.text = brand.name;
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
